package com.uuah.server.bootstrap.wrapper;

import org.tanukisoftware.wrapper.WrapperListener;
import org.tanukisoftware.wrapper.WrapperManager;

import com.uuah.server.UuahServer;

public class UuahServerWrapper implements WrapperListener {
	private UuahServer uuahServer;

	public UuahServerWrapper() {
		super();
	}

	public Integer start(String[] args) {
		try {
			uuahServer = new UuahServer(args);
			uuahServer.start(false);
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return new Integer(1);
		}
	}

	public int stop(int exitCode) {
		uuahServer.shutdown();
		return exitCode;
	}

	public void controlEvent(int event) {
		if (WrapperManager.isControlledByNativeWrapper()) {
		} else {
			if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT)
					|| (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT)
					|| (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) {
				WrapperManager.stop(0);
			}
		}
	}
}
